package com.shisfish.library.Utils;

import java.util.Random;

public class RandomUtils {
	
	/** 最大随机数长度 */
	public static final int MAX_LENGTH = 20;
	
	/** 全部字符 */
	public static final String ALL_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~-&^%$#@abcdefghijklmnopqrstuvwxyz0123456789";
	
	/** 全部字符长度 */
	public static final int ALL_STRING_LENGTH = ALL_STRING.length();
	
	public static final String Less_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	
	public static final int Less_STRING_LENGTH = Less_STRING.length();
	
	/**
	 * @author shisfish
	 * @date 2015年12月18日 下午2:38:36
	 * @Description 限定长度随机字符串
	 * @return
	 */
	public static String getRandomString() {
		
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		
		for (int i = 0; i < MAX_LENGTH; i++) {
			int number = random.nextInt(ALL_STRING_LENGTH);
			sb.append(ALL_STRING.charAt(number));
		}
		
		return sb.toString();
		
	}
	
	/**
	 * @author shisfish
	 * @date 2015年12月18日 下午2:39:06
	 * @Description 自定义长度随机字符串
	 * @param length
	 * @return
	 */
	public static String getRandomString(int length) {
	    
		Random random = new Random();     
	    StringBuffer sb = new StringBuffer();     
	   
	    for (int i = 0; i < length; i++) {     
	        int number = random.nextInt(ALL_STRING_LENGTH);     
	        sb.append(ALL_STRING.charAt(number));     
	    } 
	    
	    return sb.toString();     
	 }
	
}
